package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationMemberDto;
import com.zzyl.nursing.service.IReservationMemberService;
import com.zzyl.nursing.vo.ReservationMemberVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约Controller
 * */
@RestController
@RequestMapping("/member/reservation")
public class ReservationMemberController extends BaseController {

    @Autowired
    private IReservationMemberService reservationMemberService;
    /**
     * 取消预约
     * */
    @PutMapping("/{id}/cancel")
    public AjaxResult cancelReservation(@PathVariable Long id) {
       return AjaxResult.success(reservationMemberService.cancelReservation(id)) ;
    }
    /**
     * 分页查询
     * */
    @GetMapping("/page")
    public TableDataInfo list(Reservation reservation)
    {
        startPage();
        List<Reservation> list = reservationMemberService.selectReservationList(reservation);
        return getTable(list);
    }
    /**
     * 查询取消预约数量
     * */
    @GetMapping("/cancelled-count")
    public AjaxResult cancelledCount()
    {
        return success(reservationMemberService.selectReservationList());
    }
    /**
     * 查询每个时间段剩余预约次数
     */
    @GetMapping("/countByTime")
    public AjaxResult countByTime(long time)
    {
        List<ReservationMemberVo> reservationMemberVo = reservationMemberService.countByTime(time);
        return success(reservationMemberVo);
    }
    /**
     * 新增预约
     * */
    @PostMapping
    public AjaxResult add(@RequestBody ReservationMemberDto reservationMemberDto)
    {
       return AjaxResult.success(reservationMemberService.addReservationMember(reservationMemberDto));
    }
}
